///////////////////////////////////////////////////////////////////////////////
//
// DBT86 Project : Common Files : config.h
// Copyright (C) 2004 by Ben Hertzberg and Stanford University
// All Rights Reserved
//
// This code may not be used for any purpose without the express written
// consent of the author.  See the LICENSE.txt file for details.
//
//
// DESCRIPTION
//
// This header file contains project-wide compilation-time configuration 
// options, to enable deugging or various pieces of functionality.
//
///////////////////////////////////////////////////////////////////////////////

#ifndef __CONFIG_H__
#define __CONFIG_H__

// ASSUMPTIONS:
// 
// compiler support for 64-bit values if emulating a 64-bit platform
// compiler treats int as 32-bit
// 32-bit or 64-bit native ISA (64-bit preferred for emulating 64-bit system)
// TODO: consider little-endian assumptions
// 

// TARGET-DEPENDENT PARAMETERS (FOR ADJUSTMENT)

// Debug enable
// For MS VC builds, we add controllability to the environment's _DEBUG setting.
// However, to enable debug on any system just make sure CFG_DEBUG is set to 1 here.
#if defined(LESS86) && ((!defined(_MSC_VER)) || defined(_DEBUG))
#define CFG_DEBUG 1
#else
#define CFG_DEBUG 0
#endif

// Set to true to enable application-layer simulation (as opposed to full-system simulation).
// Note that this is only possible on apples-to-apples systems (ex: x86/Win32 on x86/Win32).
// System-level support is disabled and system calls are emulated, while the simulator is
// linked against its intended target.
#define CFG_NATIVE_PROCESS 1

#if CFG_NATIVE_PROCESS

// Stats enable
// This enables statistics collection in the runtime.  The statistics are output to
// "stats.txt" at the end of execution.
#define CFG_STATS 0


// Various studies that can be enabled when CFG_STATS is enabled
#define CFG_STUDY_MISS_SHADOWS 0

// This is necessary for proper handling of FS under Win32 when running as a native process,
// as we don't really have access to the necessary descriptors.
#if defined(WIN32) || defined(_WIN32) || defined(LINUX) || defined(__linux__)
#define CFG_NATIVE_PROCESS_FS_INTERCEPT 65536
#endif

// This is necessary for proper handling of FS and GS under Linux when running as a native 
// process, as we don't really have access to the necessary descriptors.
#if defined(LINUX) || defined(__linux__)
#define CFG_NATIVE_PROCESS_GS_INTERCEPT 65536
#endif

#endif


// Multi-CPU interpretation enable
// This enables the interpreter to simulate multiple CPUs
#define CFG_MULTI_CPU_INTERP 0

// Runtime enable
// This enables runtime hooks.  These hooks are necessary for codegen.
// Currently this represents a small overhead in interpretation, and accounts for such
// exciting features as memory management, inferring code structure, and hot spots.
#define CFG_RUNTIME 0

// Codegen enable
// This enables the code generation mechanisms, without which the system runs entirely in
// interpretation mode.  Requires CFG_RUNTIME to provide instrumentation and hooks that
// drive code generation.
#define CFG_CODEGEN 0


// set to true to force 64-bit register values
// this is different from whether the compiler supports INT64
// the basic idea is that a 32-bit processor simulates a 32-bit processor using 32-bit regvals
// TODO: currently there are 32-bit emulation things that require 64-bit regvals
//       eventually want to remove this
#define CFG_64BIT_REGVALS 1

// set to true if the guest system (example: x86) is 64-bit
#define CFG_GUEST64  0

// set to true if the host system (example: E1) is 64-bit
#define CFG_HOST64   0

// set to true if the system running the intepreter/codegen/runtime is 64-bit
#define CFG_SIMSYS64 0

// set to true if systems treat modulus with negative numbers differently from guest
#define CFG_SIMSYS_MODS_NEGATIVE_DIFFERENTLY 0

// set to true if corresponding systems don't support unaligned access
// TODO: support these
#define CFG_SIMSYS_ALIGNMENT 0
#define CFG_HOST_ALIGNMENT   0
#define CFG_GUEST_ALIGNMENT  0

// TODO: move x86-specific configuration to x86-specific configuration header
// X86 ISA extension support
#define CFG_FPU      1
#define CFG_AMDEXT   1
#define CFG_MMX      0
#define CFG_3DNOW    0
#define CFG_SSE      0
#define CFG_SSE2     0
#define CFG_SSE3     0
#define CFG_X64      0

// X86 flavor preferences
// may change operation subtly, but most obvious impact is in CPUID reporting
#define CFG_EMU_P3   0
#define CFG_EMU_P4   0
#define CFG_EMU_K7   0
#define CFG_EMU_K8   0
#define CFG_EMU_E1   1

// some basic configuration sanity checks
#if CFG_CODEGEN && !CFG_RUNTIME
#error "CFG_CODEGEN requires CFG_RUNTIME"
#endif

#if CFG_EMU_E1 && (CFG_EMU_P3 || CFG_EMU_P4 || CFG_EMU_K7 || CFG_EMU_K8)
#error "E1 emulation mode configured; deselect others"
#endif

#if CFG_EMU_P3 && (CFG_EMU_E1 || CFG_EMU_P4 || CFG_EMU_K7 || CFG_EMU_K8)
#error "P3 emulation mode configured; deselect others"
#endif

#if CFG_EMU_P4 && (CFG_EMU_E1 || CFG_EMU_P3 || CFG_EMU_K7 || CFG_EMU_K8)
#error "P4 emulation mode configured; deselect others"
#endif

#if CFG_EMU_K7 && (CFG_EMU_E1 || CFG_EMU_P3 || CFG_EMU_P4 || CFG_EMU_K8)
#error "K7 emulation mode configured; deselect others"
#endif

#if CFG_EMU_K8 && (CFG_EMU_E1 || CFG_EMU_P3 || CFG_EMU_P4 || CFG_EMU_K7)
#error "K8 emulation mode configured; deselect others"
#endif

#if CFG_SSE3 && (!CFG_SSE2 || !CFG_SSE || !CFG_MMX)
#error "SSE3 requires MMX, SSE, SSE2"
#endif

#if CFG_SSE2 && (!CFG_SSE || !CFG_MMX)
#error "SSE2 requires MMX, SSE"
#endif

#if CFG_SSE && (!CFG_MMX)
#error "SSE requires MMX"
#endif

#if CFG_EMU_K8 && !CFG_X64
#error "K8 requires X64 support"
#endif

#if CFG_EMU_P4 && !CFG_SSE2
#error "P4 requires SSE2 support"
#endif

#if CFG_X64 && !CFG_GUEST64
#error "X64 requires CFG_GUEST64 to be enabled (should work, albeit slowly, on 32-bit systems)"
#endif

#if CFG_X64 && !CFG_AMDEXT
#error "X64 requires AMD extensions to be enabled"
#endif

// IMPLEMENTATION BELOW (DON'T TOUCH)

#endif
